package com.atguigu.staservice.controller;


import com.atguigu.commonutils.Result;
import com.atguigu.staservice.service.StatisticsDailyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author zr
 * @since 2021-11-26
 */
@RestController
@RequestMapping("/sta/service/statistics")
//@CrossOrigin
@Api(tags = "统计分析")
public class StatisticsDailyController {
    @Resource
    private StatisticsDailyService statisticsDailyService;

    @ApiOperation("统计某天的注册人数")
    @PostMapping("registerCount/{day}")
    public Result registerCount(@PathVariable String day) {
        statisticsDailyService.registerCount(day);
        return Result.ok();
    }

    /**
     * 显示图表数据 返回两部分数据 日期json数组 数量json数组
     *
     * @param type  查询因子
     * @param begin 开始日期
     * @param end   结束日期
     * @return
     */
    @ApiOperation("图表显示")
    @GetMapping("getChartData/{type}/{begin}/{end}")
    public Result getChartData(@PathVariable String type, @PathVariable String begin, @PathVariable String end) {
        Map<String, Object> map = statisticsDailyService.getChartData(type, begin, end);
        return Result.ok(map);
    }
}

